package com.hengli.mapper;

import com.github.pagehelper.Page;
import com.hengli.annotation.AutoFill;
import com.hengli.dto.WinepackagePageQueryDTO;
import com.hengli.entity.Winepackage;
import com.hengli.enumeration.OperationType;
import com.hengli.vo.WineItemVO;
import com.hengli.vo.WinepackageVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface WinepackageMapper {

    /**
     * 根据id修改套餐
     * @param winepackage
     */
    @AutoFill(OperationType.UPDATE)
    void update(Winepackage winepackage);

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from winepackage where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 分页查询
     * @param winepackagePageQueryDTO
     * @return
     */
    Page<WinepackageVO> pageQuery(WinepackagePageQueryDTO winepackagePageQueryDTO);

    /**
     * 新增套餐
     */
    @AutoFill(OperationType.INSERT)
    void save(Winepackage winepackage);

    /**
     * 根据主键id查询套餐
     * @param id
     * @return
     */
    @Select("Select * from winepackage where id = #{id}")
    Winepackage getById(Long id);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Delete("Delete from winepackage where id = #{id}")
    void deleteById(Long id);



    /**
     * 动态条件查询套餐
     * @param winepackage
     * @return
     */
    List<Winepackage> list(Winepackage winepackage);

    /**
     * 根据套餐id查询菜品选项
     * @param winepackageId
     * @return
     */
    @Select("select ww.name, ww.copies, w.image, w.description " +
            "from winepackage_wine ww left join wine w on ww.wine_id = w.id " +
            "where ww.winepackage_id = #{winepackageId}")
    List<WineItemVO> getWineItemByWinepackageId(Long winepackageId);

    /**
     * 根据条件统计套餐数量(工作台使用)
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
